unit unova;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
  StdCtrls,udata;

type

  { Tnova }

  Tnova = class(TForm)
    ButtonPanel1: TButtonPanel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure CancelButtonClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure CaseOfDicUppend;
    procedure CaseOfDicRewrite;
    procedure OKButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  nova: Tnova;
  id_str:String;

implementation
uses dic_oneforfour, umain;
{$R *.lfm}

{ Tnova }

procedure Tnova.CancelButtonClick(Sender: TObject);
begin
  Close;
end;

procedure Tnova.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  Label2.Visible:=false;
  Edit2.Visible:=false;
   Edit1.Text:='';
   Edit2.Text:='';
end;

procedure Tnova.FormShow(Sender: TObject);
begin
  Label1.Caption:= dic_oneforfive.DBGrid1.Columns[1].Title.Caption;
case insorupdate of
     1:
       begin
         nova.Caption:='Створення нового запису';
         if WhatIsForm=5 then begin
           Label2.Caption:=dic_oneforfive.DBGrid1.Columns[2].Title.Caption;;
           Label2.Visible:=true;
           Edit2.Visible:=true;
         end;
         Edit1.SetFocus;
       end;
     2:
       begin
         nova.Caption:='Редагування запису';
         if WhatIsForm<>5 then begin
           Edit1.Text:=DataModule1.DIC_SQLQuery.Fields[1].AsString;
         end
         else begin
           Label2.Caption:=dic_oneforfive.DBGrid1.Columns[2].Title.Caption;;
           Label2.Visible:=true;
           Edit2.Visible:=true;
           Edit1.Text:=DataModule1.DIC_SQLQuery.Fields[1].AsString;
           Edit2.Text:=DataModule1.DIC_SQLQuery.Fields[2].AsString;
         end;
         Edit1.SetFocus;
       end;
     3:
       begin
         nova.Caption:='Копіювання запису';
         if WhatIsForm<>5 then begin
           Edit1.Text:=DataModule1.DIC_SQLQuery.Fields[1].AsString
         end
         else begin
           Label2.Caption:=dic_oneforfive.DBGrid1.Columns[2].Title.Caption;;
           Label2.Visible:=true;
           Edit2.Visible:=true;
           Edit1.Text:=DataModule1.DIC_SQLQuery.Fields[1].AsString;
           Edit2.Text:=DataModule1.DIC_SQLQuery.Fields[2].AsString;
         end;
         Edit1.SetFocus;
       end;
end;
   DataModule1.DIC_SQLQueryWRITE.Close;
   DataModule1.DIC_SQLQueryWRITE.SQL.Clear;
end;

procedure Tnova.CaseOfDicUppend;
begin
     case WhatIsForm of
        1:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_OZNAKI_PROCEDURE (-1,'''+ Edit1.Text+''')';
        2:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_KATEGORIYA_PROCEDURE (-1,'''+ Edit1.Text+''')';
        3:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_POSADI_PROCEDURE (-1,'''+ Edit1.Text+''')';
        4:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_PIDROZDIL_PROCEDURE (-1,'''+ Edit1.Text+''')';
        5:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_PLANRAH_PROCEDURE (-1,'''+ Edit1.Text+''','''+Edit2.Text+''')';
     end;
end;

procedure Tnova.CaseOfDicRewrite;
begin
   id_str:=DataModule1.DIC_SQLQuery.Fields[0].AsString;
   case WhatIsForm of
      1:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_OZNAKI_PROCEDURE ('+
                    DataModule1.DIC_SQLQuery.Fields[0].AsString+','''+Edit1.Text+''')';
      2:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_KATEGORIYA_PROCEDURE ('+
                    DataModule1.DIC_SQLQuery.Fields[0].AsString+','''+Edit1.Text+''')';
      3:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_POSADI_PROCEDURE ('+
                    DataModule1.DIC_SQLQuery.Fields[0].AsString+','''+Edit1.Text+''')';
      4:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_PIDROZDIL_PROCEDURE ('+
                    DataModule1.DIC_SQLQuery.Fields[0].AsString+','''+Edit1.Text+''')';
      5:DataModule1.DIC_SQLQueryWRITE.sql.Text:='execute procedure DIC_PLANRAH_PROCEDURE ('+
                    DataModule1.DIC_SQLQuery.Fields[0].AsString+','''+Edit1.Text+''','''+Edit2.Text+''')';
   end;
end;

procedure Tnova.OKButtonClick(Sender: TObject);
begin

  case insorupdate of
       1,3:
         begin
           CaseOfDicUppend;
         end;
       2:
         begin
           CaseOfDicRewrite;
         end;

  end;
  DataModule1.DIC_SQLQueryWRITE.ExecSQL;
  udata.DataModule1.DIC_SQLQuery.Close;
  udata.DataModule1.DIC_SQLQuery.SQL.Clear;
  dic_oneforfive.CaseSelect();

  case insorupdate of
       1:
         begin
         udata.DataModule1.DIC_SQLQuery.Last;
         end;
       2:
         begin
         udata.DataModule1.DIC_SQLQuery.Locate('Код',id_str,[]);
         end;
       3:
         begin
         udata.DataModule1.DIC_SQLQuery.Last;
         end;
  end;
end;

end.

